using UnityEngine;

namespace ProceduralPrimitivesUtil
{
	public class Pyramid : PPBase
	{
		[Header("Basic parameters")]
		public float width1 = 1f;

		public float length1 = 1f;

		public float width2 = 0.5f;

		public float length2 = 0.5f;

		public float height = 1f;

		[Header("Segments")]
		public int widthSegs = 2;

		public int lengthSegs = 2;

		public int heightSegs = 4;

		[Header("Mapping Coordinates")]
		public bool generateMappingCoords = true;

		public bool realWorldMapSize;

		public Vector2 UVOffset = new Vector2(0f, 0f);

		public Vector2 UVTiling = new Vector2(1f, 1f);

		[Header("Others")]
		public bool flipNormals;

		protected override void CreateMesh()
		{
			m_mesh.name = "Pyramid";
			length1 = Mathf.Clamp(length1, 1E-05f, 10000f);
			width1 = Mathf.Clamp(width1, 1E-05f, 10000f);
			length2 = Mathf.Clamp(length2, 1E-05f, 10000f);
			width2 = Mathf.Clamp(width2, 1E-05f, 10000f);
			height = Mathf.Clamp(height, 1E-05f, 10000f);
			lengthSegs = Mathf.Clamp(lengthSegs, 1, 100);
			widthSegs = Mathf.Clamp(widthSegs, 1, 100);
			heightSegs = Mathf.Clamp(heightSegs, 1, 100);
			float num = length1 * 0.5f;
			float num2 = width1 * 0.5f;
			float num3 = length2 * 0.5f;
			float num4 = width2 * 0.5f;
			float num5 = height * 0.5f;
			float num6 = (num2 + num4) * 0.5f;
			float num7 = (num + num3) * 0.5f;
			Vector3 vector = new Vector3(0f, num5, num3) - new Vector3(0f, 0f - num5, num);
			Vector3 vector2 = new Vector3(num4, num5, 0f) - new Vector3(num2, 0f - num5, 0f);
			float magnitude = vector.magnitude;
			float magnitude2 = vector2.magnitude;
			vector = vector.normalized;
			vector2 = vector2.normalized;
			Vector3 vector3 = new Vector3(0f, vector.y, 0f - vector.z);
			Vector3 vector4 = new Vector3(0f - vector2.x, vector2.y, 0f);
			CreateTrapezoid(pivotOffset + m_rotation * new Vector3(0f, 0f, num7), m_rotation * vector, m_rotation * Vector3.left, width1, width2, magnitude, 0f, widthSegs, heightSegs, generateMappingCoords, realWorldMapSize, UVOffset, UVTiling, flipNormals);
			CreateTrapezoid(pivotOffset + m_rotation * new Vector3(0f, 0f, 0f - num7), m_rotation * vector3, m_rotation * Vector3.right, width1, width2, magnitude, 0f, widthSegs, heightSegs, generateMappingCoords, realWorldMapSize, UVOffset, UVTiling, flipNormals);
			CreateTrapezoid(pivotOffset + m_rotation * new Vector3(0f - num6, 0f, 0f), m_rotation * vector4, m_rotation * Vector3.back, length1, length2, magnitude2, 0f, lengthSegs, heightSegs, generateMappingCoords, realWorldMapSize, UVOffset, UVTiling, flipNormals);
			CreateTrapezoid(pivotOffset + m_rotation * new Vector3(num6, 0f, 0f), m_rotation * vector2, m_rotation * Vector3.forward, length1, length2, magnitude2, 0f, lengthSegs, heightSegs, generateMappingCoords, realWorldMapSize, UVOffset, UVTiling, flipNormals);
			CreatePlane(pivotOffset + m_rotation * new Vector3(0f, num5, 0f), m_rotation * Vector3.forward, m_rotation * Vector3.right, width2, length2, widthSegs, lengthSegs, generateMappingCoords, realWorldMapSize, UVOffset, UVTiling, flipNormals);
			CreatePlane(pivotOffset + m_rotation * new Vector3(0f, 0f - num5, 0f), m_rotation * Vector3.forward, m_rotation * Vector3.left, width1, length1, widthSegs, lengthSegs, generateMappingCoords, realWorldMapSize, UVOffset, UVTiling, flipNormals);
		}
	}
}
